package net.xdclass.rbac_shiro.service.Impl;

import net.xdclass.rbac_shiro.dao.RoleMapper;
import net.xdclass.rbac_shiro.dao.UserMapper;
import net.xdclass.rbac_shiro.domain.Role;
import net.xdclass.rbac_shiro.domain.User;
import net.xdclass.rbac_shiro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created whit IntelliJ IDEA
 * User:杨骏杰
 * Date:2021/2/15
 * Time:21:10
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private RoleMapper roleMapper;

    @Resource
    private UserMapper userMapper;

    @Override
    public User findAllUserInfoByUserName(String username) {
        User user = userMapper.findByUserName(username);
        //查询用户的角色集合
        List<Role> roleList = roleMapper.findRoleListByUserId(user.getId());

        user.setRoleList(roleList);
        return user;
    }

    @Override
    public User findSimpleUserInfoById(int userId) {
        return userMapper.findByid(userId);
    }

    @Override
    public User findSimpleUserInfoByUserName(String username) {
        return userMapper.findByUserName(username);
    }
}
